<?php
//Cette fonction vérifie si le mimetype commence par "image"
function is_pic($path)
{
	$finfo = finfo_open(FILEINFO_MIME_TYPE);
	$type = finfo_file($finfo, $path); 
	$type = explode("/",$type);
	return $type[0] == "image";
}

//On affiche 12 images par page
$NumPicPage = 12;

if (!isset($_GET['page']))
{
	$_GET['page'] = 1;
}

$pics = array();
$dirname = 'Locations/'.$_GET['id']."/";
$dir = opendir($dirname); 

while($file = readdir($dir)) {
	if($file != '.' && $file != '..' && !is_dir($dirname.$file) && is_pic($dirname.$file) && ($file == "default.png" || substr($file,0,4) == "oui_"))
	{
		$pics[] = $file;
	}
}

closedir($dir);

$NumberOfPics = count($pics);
$NumberOfPages = ($NumberOfPics - $NumberOfPics % $NumPicPage) / $NumPicPage;
if ($NumberOfPics % $NumPicPage > 0)
{
	$NumberOfPages += 1;
}

if ($_GET['page'] > 1)
{
	echo '<div style="width:92px; height:92px; cursor:pointer; float:left;" onclick="fader(\'locationpics\',0,100,1000);this.parentNode.innerHTML = ajaxinclude(\'location_minpic.php?id='.$_GET['id'].'&page='.($_GET['page']-1).'\');"><img src="CSS/left.png"></div>';
}
else
{
	echo '<div style="width:92px; height:92px; float:left;"></div>';
}
	
	for ($i = 0; $i < $NumPicPage; $i++)
	{
		$NumCurrentPic = ($_GET['page']-1)*$NumPicPage+$i;
		if ($NumberOfPics > $NumCurrentPic)
		{
			echo '<a id="pic'.$NumCurrentPic.'" href="'.$dirname.$pics[$NumCurrentPic].'" rel="lightbox[location'.$_GET['id'].']"><img src="'.$dirname.$pics[$NumCurrentPic].'" class="minpic" onmouseover="fader(\'pic'.$NumCurrentPic.'\',50,100,1000);"/></a>';
		}
	}
	
if ($_GET['page'] < $NumberOfPages)
{
	echo '<span style="cursor:pointer;" onclick="fader(\'locationpics\',0,100,1000);this.parentNode.innerHTML = ajaxinclude(\'location_minpic.php?id='.$_GET['id'].'&page='.($_GET['page']+1).'\');fader(\'locationpics\',0,1,1000);"><img src="CSS/right.png"></span>';
}
?>
